package mo.qmul.gemom;


import java.util.Date;
import java.util.Vector;
/** COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu Jinfu Wang------------QMUL
 * @version 1.0 
 * */
public class TopicData {
	
	 private String _namespace;
	 private String _topic;
	 private Vector<Field> _data;
	 
	 private int Size=200;

	
	
	 public TopicData(String ns, String t)
	 {
		 
		 _namespace=ns;
		 
		 _topic=t;
		 
		 _data= new Vector<Field>();
		 
	 }
	 
	 
	 
	 public String getNamespace(){
		 
		 return _namespace;
	 }
	 
	 
	 public String getTopic(){
		 
		 return _topic;
	 }
	 
	 
	 
	 public Vector<Field> getData()
	 {
		 
		 return _data;
	 }
	 
	 public void addData(Field d)
	 {
		 
		 if(_data.size()<Size)
		 {
			 _data.add(d);
		 }
			 
	 }
	 
	 
	 public boolean equal(String ns, String tp)
	 {
		 
		 if((_namespace.equalsIgnoreCase(ns))&&(_topic.equalsIgnoreCase(tp)))
			 
			 return true;
		 else
			 
			 return false;
		 
	 }
	 
	 
	 public double getState(){
		 
		 double s=0;
		 
		 for(int i=0; i< _data.size(); i++)
		 {
			 
			 s=_data.get(i).getValue()+s;
			 
		 }
		 
		 s=s/_data.size();
		 
		 return s; 
	 }
	 
	
	 
	 
	 

}

class Field{
	 
	 
	private Date _time;
	private String _key;
	 
	 private String _value;
	 
	 
	 
	 public Field(String k, String v)
	 {

		 _key=k;
		 _value=v;
	 }
	
	 
	 public String getTime()
	 {
		 String time;
		 
		 time=""+_time.getHours()+_time.getMinutes()+_time.getSeconds();
		 
		 return time;
	 }
	 
	 public String getKey(){
		 
		 return _key;
	 }
	 
	 
	 public double getValue(){
		 
		 return Double.parseDouble(_value);
	 }
	 
	 
}
